package com.zl.csMall.mine.recAddress.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.csMall.mine.recAddress.po.RecAddress;
import com.zl.csMall.mine.recAddress.mapper.RecAddressMapper;
import com.zl.csMall.mine.recAddress.service.RecAddressService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: RecAddressServiceImpl
 * @author: ChenNing
 * @date 2025-10-15 17:38
 */
@Service
public class RecAddressServiceImpl extends ServiceImpl<RecAddressMapper, RecAddress> implements RecAddressService {


    @Override
    public List<RecAddress> getByUserId(long userId) {
        LambdaQueryWrapper<RecAddress> recAddressQuery = new LambdaQueryWrapper<>();
        recAddressQuery.eq(RecAddress::getUserId, userId).orderByDesc(RecAddress::getCreateDate);
        return this.list(recAddressQuery);
    }

    @Override
    public void cancelDefault(long userId) {
        LambdaUpdateWrapper<RecAddress> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(RecAddress::getIsDefault, 2)
                .eq(RecAddress::getUserId, userId)
                .eq(RecAddress::getIsDefault, 1);
        this.update(updateWrapper);
    }

}
